The drawn tile index at (x, y) in the current room’s own tileset right now - the getter twin of tile_set_index, for reading back what a cell currently shows (its authored picture, or whatever a project’s own tile_set_index call last changed it to).
tile_index(x, y, layer = ROOM_LAYER_MAIN) -> int| Name | Type |
|---|---|
x | real |
y | real |
layer | room_layer (can be left out; then it is ROOM_LAYER_MAIN) |
int
The drawn tile index at (x, y) in the current room's own tileset, right now - the getter twin of tile_set_index, for reading back what a cell currently shows: either its authored picture, or whatever a project's own tile_set_index call last changed it to.
x and y are a place in the room, counted from the room's top-left corner. That is also where the tile grid starts, so the very first tile covers x from 0 to 7 and y from 0 to 7 (tiles are 8 by 8 pixels).
Unlike tile_set_index, this always works - the same "reading always succeeds, only the write is budget-gated" relationship tile_flags already has to tile_set_class/tile_set_flags. A room too large for this engine's live-mutable drawing budget still reads back its true, unchanged picture through this function; it simply cannot be repainted through tile_set_index.
Returns -1 if the current room has no drawn tile layer at all, or if (x, y) falls outside it. This is not the TILE_SOLID "out of map" sentinel tile_flags returns for the same situation - there is no equivalent "always solid" convention for a picture, and -1 is never a valid tile index, so it can never be mistaken for a real one.
A tile layer other than Main. The optional last argument, layer, picks which of the room's tile layers to read: ROOM_LAYER_MAIN (the room's own tiles, and what you get when you leave the argument out), ROOM_LAYER_FRONT or ROOM_LAYER_BACK. A room that does not have that layer gives -1. A Front or Back layer always reads, as Main does, and a layer that is hidden with room_layer_visible still reads. A game that never names a layer does not carry any of the extra code.
if (tile_index(x + 8, y) != 0) {
// the cell ahead is not showing the open-floor tile yet
}
if (tile_index(x, y, ROOM_LAYER_FRONT) != 0) {
// the Front layer has a tile over this spot
}The first check asks whether the cell just ahead of the walker is already showing tile index 0 (this tileset's own open-floor picture) - useful for skipping a redundant tile_set_index call, or for deciding whether a cell has already been dug without needing a separate tracking variable. The second asks the room's Front layer instead of its own tiles.
Unlike tile_set_index, this ALWAYS works, the same “read always succeeds, only the write is budget-gated” relationship tile_flags has to tile_set_class/tile_set_flags: a room too large for this engine’s live-mutable drawing budget still reads back its true, unchanged picture, it just cannot be repainted. Returns -1 if the current room has no drawn tile layer at all, or if (x, y) falls outside it - never the TILE_SOLID “out of map” sentinel tile_flags uses; -1 is not a valid tile index, so it can never be mistaken for a real one. The optional last argument is the tile layer to read: ROOM_LAYER_MAIN (the default, the room’s own tiles), ROOM_LAYER_FRONT or ROOM_LAYER_BACK. A room with no such layer gives -1. A Front or Back layer always reads, as Main does.